package com.epfresh.views.dialog;

import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.epfresh.R;
import com.epfresh.activity.MoreEvaluateActivity;
import com.epfresh.api.utils.LocalDisplay;
import com.epfresh.api.utils.T;
import com.epfresh.bean.StoreDetail;
import com.epfresh.utils.CommonUtils;
import com.epfresh.views.stick.StickyScrollView;

/**
 * @author wangzhanghuan
 * @version 1.0
 * @date create 17-2-20
 * @Description
 */
@Deprecated
public class DcInfoDialog extends BaseDialogView implements View.OnClickListener {

    private TextView tvMarket;
    private TextView tvAddress;
    private TextView tvPhone;
    private TextView tvPayment;
    private TextView tvDiscount;
    private TextView tvDelivery;
    private TextView tvCert;
    private TextView tvRate;
    private TextView tvAmount;
    private TextView tvAcceptTime;
    private View llRate;


    private StoreDetail storeDetail;


    public DcInfoDialog(Context context) {
        super(context);
        init();
    }

    @Override
    public void initBefore() {
        setGravity(Gravity.TOP);
    }

    private void init() {


        View view = LayoutInflater.from(context).inflate(R.layout.view_store_info, contentContainer);

        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) rootView.getLayoutParams();
        lp.topMargin = LocalDisplay.dp2px(108);
        setCancelable(true);

        tvMarket = (TextView) view.findViewById(R.id.tv_market);
        tvAddress = (TextView) view.findViewById(R.id.tv_address);
        tvPhone = (TextView) view.findViewById(R.id.tv_phone);
        tvPayment = (TextView) view.findViewById(R.id.tv_payment);
        tvDiscount = (TextView) view.findViewById(R.id.tv_discount);
        tvDelivery = (TextView) view.findViewById(R.id.tv_delivery);
        tvCert = (TextView) view.findViewById(R.id.tv_cert_status);
        tvRate = (TextView) view.findViewById(R.id.tv_rate);
        tvAmount = (TextView) view.findViewById(R.id.tv_amount);
        tvAcceptTime = (TextView) view.findViewById(R.id.tv_accept_time);
        llRate = view.findViewById(R.id.ll_comment);
        view.findViewById(R.id.iv_rate).setOnClickListener(this);
        view.findViewById(R.id.tv_rate).setOnClickListener(this);

//        llRate.setOnClickListener(this);

        view.findViewById(R.id.ll_phone).setOnClickListener(this);
        updateStoreStatus();

    }


    public void updateData(StoreDetail storeDetail) {
        this.storeDetail = storeDetail;
        updateStoreStatus();

    }


    public void updateStoreStatus() {
        if (tvMarket != null) {
            if (storeDetail != null) {

                tvMarket.setText(storeDetail.getMarketName());
                tvAddress.setText(storeDetail.getAddress());
                tvPhone.setText(storeDetail.getManagerPhone());
                tvPayment.setText(storeDetail.getPaymentInfo());
                tvDiscount.setText(storeDetail.getDiscount());
                tvDelivery.setText(storeDetail.getDeliveryInfo());
                tvCert.setText(storeDetail.getCert());
                tvAmount.setText(storeDetail.getOrderCount() + "单");
                tvRate.setText(storeDetail.getGoodCommentsRate() + "好评率");
                String businessTime = storeDetail.getBusinessTime();
                if (businessTime == null || "".equals(businessTime)){
                    tvAcceptTime.setText("00:00-24:00");
                }else {

                    tvAcceptTime.setText(businessTime);
                }
            } else {
                tvMarket.setText("");
                tvAddress.setText("");
                tvPhone.setText("");
                tvPayment.setText("");
                tvDiscount.setText("");
                tvDelivery.setText("");
                tvCert.setText("");
                tvAmount.setText("");
                tvRate.setText("");
            }
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_more_dc:
//                intoMoreDc();

                break;
            case R.id.iv_rate:
            case R.id.tv_rate:
                intoComment();

                break;
            case R.id.ll_phone:
                String managerPhone = storeDetail.getManagerPhone();
                if (managerPhone != null && !"".equals(managerPhone))
                    CommonUtils.intoPhone(context, managerPhone);

                break;
        }
    }

    private void intoComment() {
        Intent more = new Intent(context, MoreEvaluateActivity.class);
        if (storeDetail == null) {
            T.toast("数据已过期，请重载应用");
        }
        more.putExtra("evaluate_percent", storeDetail.getGoodCommentsRate());
        more.putExtra("storeId", storeDetail.getId());
        context.startActivity(more);
    }


}
